class OperatingDatabase:
	#给某个可能的属性留空
	#给某个可能的属性留空
	#给某个可能的属性留空
	def __init__(self):#初始化方法但是我不知道该怎么用，大概是先连接数据库？——构造方法实现数据库连接
		import pymysql

		db = pymysql.connect(host='localhost',user='root',password='',db='',charset='utf8')
		
		cursor = db.cursor()

		cursor.execute('create database if not exists stusystem')

		cursor.execute('use stusystem')

		cursor.execute('Create table if not exists stuinfo (id int(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,name varchar(32) NOT NULL, age int(10) unsigned NOT NULL default 20, classname varchar(32) NOT NULL) ')
		#设置默认信息
		cursor.execute('insert ignore into stuinfo(id,name,age,classname) values(1,"Able",20,"Python01") ')

		cursor.execute('insert ignore into stuinfo(id,name,age,classname) values(2,"Baker",20,"Python02") ')

		cursor.execute('insert ignore into stuinfo(id,name,age,classname) values(3,"Charlie",20,"Python03") ')

		cursor.execute('insert ignore into stuinfo(id,name,age,classname) values(4,"Dog",20,"Python04") ')

		cursor.execute('insert ignore into stuinfo(id,name,age,classname) values(5,"Easy",20,"Python05") ')

		cursor.execute('insert ignore into stuinfo(id,name,age,classname) values(6,"Fox",20,"Python06") ')

		cursor.execute('insert ignore into stuinfo(id,name,age,classname) values(7,"George",20,"Python07") ')

		cursor.execute('insert ignore into stuinfo(id,name,age,classname) values(8,"How",20,"Python08") ')

		cursor.execute('insert ignore into stuinfo(id,name,age,classname) values(9,"Item",20,"Python09") ')

		cursor.execute('insert ignore into stuinfo(id,name,age,classname) values(10,"Jig",20,"Python10") ')

		db.commit()

	def findallinfo(self):#全部查询方法

		import pymysql

		db = pymysql.connect(host='localhost',user='root',password='',db='stusystem',charset='utf8')

		cursor = db.cursor()

		cursor.execute('select * from stuinfo')

		alist=cursor.fetchall()

		for vo in alist:

			print(vo)
			#print(type(vo)) 结果是tuple。

	def dropstuinfo(self):#删除方法

		the_delete_id=int(input('请输入要删除的学生ID'))

		import pymysql

		db = pymysql.connect(host='localhost',user='root',password='',db='stusystem',charset='utf8')

		cursor = db.cursor()

		#the_sql_deleteorder="delete * from stuinfo where id = '%d' "% (the_delete_id)

		the_sql_deleteorder="delete from stuinfo where id = '%d' "% (the_delete_id)#没有括号会如何？我没试过。

		cursor.execute(the_sql_deleteorder)

		db.commit()

	def addstuinfo(self):#添加学生

		the_id=int(input('请输入学生ID'))

		the_name=input('请输入学生姓名')

		the_age=int(input('请输入学生年龄'))

		the_classname=input('请输入学生课程名称')

		import pymysql

		db = pymysql.connect(host='localhost',user='root',password='',db='stusystem',charset='utf8')

		cursor = db.cursor()

		the_sql_order="insert ignore into stuinfo(id,name,age,classname) values('%d','%s','%d','%s')" %(the_id,the_name,the_age,the_classname)

		cursor.execute(the_sql_order)

		db.commit()

		#cursor.execute('insert into testb(id,name,age,classname) values(9,"Baker",25,"Python01") ')#为什么实例化会无效？

		#cursor.execute('select * from testb')#

		#data=cursor.fetchall()

		#print(data)